package com.abc.example.controller;

import com.abc.example.entity.Orgnization;
import com.abc.example.service.OrgnizationManService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import io.gitee.shengzheng1999.esbcommon.vo.common.BaseResponse;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @className	: OrgnizationManController
 * @description	: 组织机构对象管理控制器类
 * @summary		: 
 * @history		:
 * ------------------------------------------------------------------------------
 * date			version		modifier		remarks
 * ------------------------------------------------------------------------------
 * 2024/01/14	1.0.0		sheng.zheng		初版
 *
 */
@RequestMapping("/orgnization")
@RestController
public class OrgnizationManController extends BaseController{
	// 组织机构对象服务类对象
	@Autowired
	private OrgnizationManService orgnizationManService;
	
	/**
	 * @methodName		: addItem
	 * @description		: 新增一个组织机构对象
	 * @see			    : {@link OrgnizationManService#addItem}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/add")
	public BaseResponse<Map<String,Object>> addItem(HttpServletRequest request,
			@RequestBody Orgnization item) {
		Map<String,Object> map = orgnizationManService.addItem(request, item);
		return successResponse(map);
	}

	/**
	 * @methodName		: editItem
	 * @description		: 根据key修改一个组织机构对象
	 * @see			    : {@link OrgnizationManService#editItem}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/edit")
	public BaseResponse<Object> editItem(HttpServletRequest request,
			@RequestBody Map<String, Object> params) {
		orgnizationManService.editItem(request, params);
		return successResponse();
	}

	/**
	 * @methodName		: deleteItem
	 * @description		: 根据key禁用/启用一个组织机构对象
	 * @see			    : {@link OrgnizationManService#deleteItem}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/delete")
	public BaseResponse<Object> deleteItem(HttpServletRequest request,
			 @RequestBody Map<String, Object> params) {
		orgnizationManService.deleteItem(request, params);
		return successResponse();
	}

	/**
	 * @methodName		: queryItems
	 * @description		: 根据条件分页查询组织机构对象列表
	 * @see			    : {@link OrgnizationManService#queryItems}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/query")
	public BaseResponse<List<Orgnization>> queryItems(HttpServletRequest request,
			 @RequestBody Map<String, Object> params) {
		PageInfo<Orgnization> pageInfo = orgnizationManService.queryItems(request, params);
		return successResponse(pageInfo);
	}

	/**
	 * @methodName		: getItem
	 * @description		: 根据key获取一个组织机构对象
	 * @see			    : {@link OrgnizationManService#getItem}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/getItem")
	public BaseResponse<Orgnization> getItem(HttpServletRequest request,
			 @RequestBody Map<String, Object> params) {
		Orgnization item = orgnizationManService.getItem(request, params);
		return successResponse(item);
	}

	/**
	 * @methodName		: getItems
	 * @description		: 根据条件查询组织机构对象列表
	 * @see			    : {@link OrgnizationManService#getItems}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/getItems")
	public BaseResponse<List<Orgnization>> getItems(HttpServletRequest request,
			 @RequestBody Map<String, Object> params) {
		List<Orgnization> itemList = orgnizationManService.getItems(request, params);
		return successResponse(itemList);
	}

	/**
	 * @methodName		: importExcelFile
	 * @description		: 导入组织机构对象数据Excel文件
	 * @see			    : {@link OrgnizationManService#importExcelFile}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/import", method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public BaseResponse<List<String>> importExcelFile(HttpServletRequest request,
			@RequestPart(value="file",required=true) MultipartFile upfile,
			@RequestPart(value="params") String params) {
		Map<String,Object> map= JSON.parseObject(params, Map.class);
		List<String> errorList = orgnizationManService.importExcelFile(request,upfile,map);
		return successResponse(errorList);
	}           

        
	/**
	 * @methodName		: exportExcelFile
	 * @description		: 导出组织机构对象Excel数据文件
	 * @see			    : {@link OrgnizationManService#exportExcelFile}
	 * @history			:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks
	 * ------------------------------------------------------------------------------
	 * 2024/01/14	1.0.0		sheng.zheng		初版
	 *
	 */
	@RequestMapping("/export")
	public void exportExcelFile(HttpServletRequest request,
			 HttpServletResponse response, @RequestBody Map<String, Object> params) {
		orgnizationManService.exportExcelFile(request, response, params);
	}    
}